package com.zmz.lambda;

import java.util.ArrayList;
import java.util.List;

/**
 * Create with IntelliT IDEA
 *
 * @Author: zhengmingzhe
 * @Date: 2022/07/30/19:57
 * @Description: 用lambda表达式删除集合
 */
public class Lambda07 {
    public static  void main(String [] args) {
        List<Item2> list = new ArrayList<>();
        list.add(new Item2(1, "阿萨", 12.22));
        list.add(new Item2(2, "撒旦", 12.21));
        list.add(new Item2(3, "答案", 11.22));


        //以前的方法 删除id=3的元素
        for(Item2 item2:list){
            if(item2.id==3){
                list.remove(item2);
                break;
            }
        }
        list.forEach(t->System.out.println(t));

        //使用lambda移除id=3的元素
        list.removeIf(t->{
         return t.getId() ==3;
        });
        list.forEach(t->System.out.println(t));

        list.removeIf(t-> t.getId() ==3);
        list.forEach(t->System.out.println(t));
    }
}
